#include <QApplication>
#include <QQmlApplicationEngine>
#include <QtQml>
#include <QFontDatabase>
#include "user.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QQmlApplicationEngine engine;

    // 加载本地字体库 与qtquickcontrols2.conf配合 此文件需添加进资源文件
    int localFont = QFontDatabase::addApplicationFont(QGuiApplication::applicationDirPath() + "/fonts/MiSans-Normal.ttf");
    QFontDatabase::applicationFontFamilies(localFont);


    const QUrl url(u"qrc:/canFilterTool/main.qml"_qs);
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);

    user *mUser = new user();

    app.installNativeEventFilter(mUser->getSerialEventClass());

    engine.rootContext()->setContextProperty("user", mUser);
    engine.rootContext()->setContextProperty("serial", mUser->getSerialClass());
    engine.rootContext()->setContextProperty("serialEvent", mUser->getSerialEventClass());

    engine.load(url);

    return app.exec();
}
